const Cesium = window.Cesium;
import { formarColor, COLOR } from "../../Config";

class Icon {
    constructor(Entity, options) {
        if (!Entity) {
            throw new Error('至少传入一个 Entity 对象');
        };
        this.FontSize = window.REMFontSize || 1;
        this.Entity = Entity;
        this.Url2D = options.imageUrl;
        this.Url3D = options.imageUrl3D;
        this.color = formarColor(options.color || COLOR.DEFAULT);
		this.imageSizeWidth = options.imageSizeWidth || parseInt(32 * this.FontSize);
		this.imageSizeHeight = options.imageSizeHeight || parseInt(32 * this.FontSize);
		this.image3DSize = options.image3DSize || parseInt(48 * this.FontSize);
        this.rotation = options.rotation;
        this.Entity = Entity;
    }
    set show(type) {
        if (this.Entity.billboard) {
            this.Entity.billboard.show = !!type;
        };
        if (this.Entity.model) {
            this.Entity.model.show = !!type;
        };
    }
    get show() {
        if (this.Entity.billboard) {
            return this.Entity.billboard.show
        };
        if (this.Entity.model) {
            return this.Entity.model.show
        }
    }
    changeSenceType(type) {
        if (type == '3D' && this.Url3D) {
            this.Entity.billboard = null;
            this.Entity.model = this.render3DIcon();
        } else {
            this.Entity.billboard = this.render2DIcon()
            this.Entity.model = null;
        }
    }
    changeRotation(rotation) {
        if (this.Entity.billboard) {
            this.Entity.billboard.rotation = rotation;
        }
    }
    render2DIcon() {
        return new Cesium.BillboardGraphics({
            // 图标地址
            image: this.Url2D,
            // 宽度
            width: this.imageSizeWidth,
            // 高度
            height: this.imageSizeHeight,
            // 旋转
            rotation: this.rotation,
            // 颜色
            color: this.color,
            // 世界空间中的对齐轴
            alignedAxis: Cesium.Cartesian3.ZERO,
            //alignedAxis: Cesium.Cartesian3.UNIT_Z,
            // 水平对齐方式
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            // 垂直对齐方式
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            // 贴地
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
        });
    }
    render3DIcon() {
        return new Cesium.ModelGraphics({
            uri: this.Url3D,
            minimumPixelSize: this.image3DSize,
            maximumScale: 20000,
        });
    }

}



export { Icon }
